import { applyReviver as a } from '../doc/applyReviver.js';
import { NODE_TYPE as f, isDocument as u } from './identity.js';
import { toJS as m } from './toJS.js';
class g {
  constructor(e) {
    Object.defineProperty(this, f, { value: e });
  }
  /** Create a copy of this node.  */
  clone() {
    const e = Object.create(
      Object.getPrototypeOf(this),
      Object.getOwnPropertyDescriptors(this),
    );
    return this.range && (e.range = this.range.slice()), e;
  }
  /** A plain JavaScript representation of this node. */
  toJS(e, { mapAsMap: c, maxAliasCount: r, onAnchor: o, reviver: s } = {}) {
    if (!u(e)) throw new TypeError('A document argument is required');
    const n = {
        anchors: /* @__PURE__ */ new Map(),
        doc: e,
        keep: !0,
        mapAsMap: c === !0,
        mapKeyWarned: !1,
        maxAliasCount: typeof r == 'number' ? r : 100,
      },
      t = m(this, '', n);
    if (typeof o == 'function')
      for (const { count: i, res: p } of n.anchors.values()) o(p, i);
    return typeof s == 'function' ? a(s, { '': t }, '', t) : t;
  }
}
export { g as NodeBase };
